{% extends "base.html" %}
{% load debate_tags i18n humanize %}

{% block page-title %}
  {% if use_code_names %}
    {% blocktrans trimmed with matchup=debate.matchup_codes %}
      Ballot for {{ matchup }}
    {% endblocktrans %}
  {% else %}
    {% blocktrans trimmed with matchup=debate.matchup %}
      Ballot for {{ matchup }}
    {% endblocktrans %}
  {% endif %}
{% endblock %}
{% block head-title %}
  {% if use_code_names %}
    {% blocktrans trimmed with matchup=debate.matchup_codes %}
      Ballot for {{ matchup }}
    {% endblocktrans %}
  {% else %}
    {% blocktrans trimmed with matchup=debate.matchup %}
      Ballot for {{ matchup }}
    {% endblocktrans %}
  {% endif %}
{% endblock %}

{% block sub-title %}
  {% blocktrans trimmed with round=debate.round.name room=debate.venue.display_name %}
    {{ round }} @ {{ room }}
  {% endblocktrans %}
{% endblock %}

{% block page-subnav-sections %}
  {% if private_url %}
    <a class="btn btn-outline-primary" href="{% tournamenturl 'privateurls-person-index' url_key %}">
      <i data-feather="chevron-left"></i>
      {% trans "Return to landing page" %}
    </a>
  {% else %}
    <a class="btn btn-outline-primary" href="{% roundurl 'results-public-round' debate.round %}">
      <i data-feather="chevron-left"></i>
      {% blocktrans trimmed with round=debate.round.name %}
        Return to Results for {{ round }}
      {% endblocktrans %}
    </a>
  {% endif %}
{% endblock %}

{% block content %}

  {% if motion.text  %}
    <div class="card">
      <div class="card-body">
        <h4 class="card-title">{% trans "Motion" %}</h4>
        {{ motion.text }}
      </div>
    </div>
  {% endif %}

  {% for sheet in result.as_dicts %}

    <div class="card mt-3">

      <div class="card-body pb-1">
        <h4 class="card-title">
          {% if sheet.adjudicator %}
            {% blocktrans trimmed with name=sheet.adjudicator.name institution=sheet.adjudicator.institution.code %}
              From {{ name }} ({{ institution }})
            {% endblocktrans %}
          {% else %}
            {% trans "Scoresheet" %}
          {% endif %}
        </h4>

        <div class="row pl-3 pt-3 p-0">

          {% for team in sheet.teams %}
            <div class="col-6 list-group mb-3">

              {% for position in team.speakers %}
                <li class="list-group-item">
                  <strong>{{ position.name }}</strong>
                  {{ position.speaker }}
                  <span class="badge badge-secondary float-right">
                    {{ position.score }}
                  </span>
                </li>
              {% endfor %}
              <li class="list-group-item list-group-item-{{ team.win_style }}">
                {% if team.total %}
                  {% if use_code_names %}
                    {% blocktrans trimmed with name=team.team.code_name side=team.side %}
                      <em>Total for {{ name }} ({{ side }})</em>
                    {% endblocktrans %}
                  {% else %}
                    {% blocktrans trimmed with name=team.team.short_name side=team.side %}
                      <em>Total for {{ name }} ({{ side }})</em>
                    {% endblocktrans %}
                  {% endif %}
                  <span class="badge badge-secondary float-right">
                    {{ team.total }}
                  </span>
                {% else %}
                  {% if use_code_names %}
                    {% blocktrans trimmed with name=team.team.code_name side=team.side %}
                      <em>{{ name }} ({{ side }})</em>
                    {% endblocktrans %}
                  {% else %}
                    {% blocktrans trimmed with name=team.team.short_name side=team.side %}
                      <em>{{ name }} ({{ side }})</em>
                    {% endblocktrans %}
                  {% endif %}
                  <span class="badge badge-secondary float-right">
                    {% if team.rank is not None %}
                      {{ team.rank|ordinal }}
                    {% else %}
                      {% if team.win %}{% trans "Won" %}{% else %}{% trans "Lost" %}{% endif %}
                    {% endif %}
                  </span>
                {% endif %}
              </li>

            </div>
          {% endfor %}

        </div>
      </div>

    </div>

  {% endfor %}

{% endblock %}
